package de.jmda.gen.java.impl;

import static org.junit.Assert.assertTrue;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.junit.Test;

import de.jmda.gen.GeneratorException;

public class JUT_DefaultAnnotationStatementsGenerator
{
	private final static Logger LOGGER =
      Logger.getLogger(JUT_DefaultAnnotationStatementsGenerator.class);

	@Test
	public void testDefaultAnnotationStatementsGenerator()
			throws GeneratorException
	{
		String input1 = "@Test1";
		String input2 = "@Test2";
		
		DefaultAnnotationStatementsGenerator generator =
				new DefaultAnnotationStatementsGenerator();

		generator.add(new DefaultAnnotationStatementGenerator(input1));
		generator.add(new DefaultAnnotationStatementGenerator(input2));
		
		StringBuffer generated = generator.generate();
		
		LOGGER.debug("generated [" + generated + "]");

		assertTrue(
				"couldn't find " + input1,
				StringUtils.contains(generated.toString(), input1));
		assertTrue(
				"couldn't find " + input2,
				StringUtils.contains(generated.toString(), input2));
	}

	@Test(expected=GeneratorException.class)
	public void testInvalidMissingAtDefaultAnnotationStatementsGenerator()
			throws GeneratorException
	{
		DefaultAnnotationStatementsGenerator generator =
				new DefaultAnnotationStatementsGenerator();

		// missing leading @
		generator.add(new DefaultAnnotationStatementGenerator("hallo"));
		
		generator.generate();
	}

	@Test(expected=GeneratorException.class)
	public void testInvalidMultipleAtDefaultAnnotationStatementsGenerator()
			throws GeneratorException
	{
		DefaultAnnotationStatementsGenerator generator =
				new DefaultAnnotationStatementsGenerator();
		
		String input = "@Test";

		// multiple identical generation statements
		generator.add(new DefaultAnnotationStatementGenerator(input));
		generator.add(new DefaultAnnotationStatementGenerator(input));

		generator.generate();
	}
}